<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='编辑用户信息'">
<meta charset="utf-8">
<header th:replace="header::headerFragment(${title})"></header>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="editForm">
							<input id="userId" name="userId" th:value="${user.userId}" type="hidden">
							<div class="form-group">
								<label class="col-sm-3 control-label">用户名：</label>
								<div class="col-sm-8">
									<input id="userName" name="userName" readonly th:value="${user.userName}" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">部门：</label>
								<div class="col-sm-8">
									<input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" readonly="readonly" id="deptName" th:field="*{dept.deptName}"> <input
										id="deptId" name="deptId" class="hidden" th:value="${user.deptId}">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">昵称：</label>
								<div class="col-sm-8">
									<input id="name" name="name" th:value="${user.name}" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">邮箱：</label>
								<div class="col-sm-8">
									<input id="email" name="email" th:value="${user.email}" class="form-control" type="email">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">手机号：</label>
								<div class="col-sm-8">
									<input id="mobile" name="mobile" th:value="${user.mobile}" class="form-control" type="tel">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">状态：</label>
								<div class="col-sm-8">
									<label class="radio-inline" th:each="dict:${@dict.getDictData('Status')}"> <input th:field="*{user.status}" type="radio" th:value="${dict.dictNo}"
										th:text="${dict.dictName}" />
									</label>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">性别：</label>
								<div class="col-sm-8">
								<label class="radio-inline" th:each="dict:${@dict.getDictData('Sex')}"> <input th:field="*{user.sex}" type="radio" th:value="${dict.dictNo}"
										th:text="${dict.dictName}" />
									</label>
								</div>
							</div>
							<input type="hidden" name="roleIds" id="roleIds" th:value="${roleIds}">
							<div class="form-group">
								<label class="col-sm-3 control-label">角色：</label>
								<div class="col-sm-8">
									<label th:each="role:${roles}" class="checkbox-inline"> <input name="role" type="checkbox" th:value="${role.roleId}" th:text="${role.roleName}"
										th:checked="${role.hasRole}" th:disabled="${role.status == '0'}">
									</label>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
									<button type="submit" class="btn btn-primary">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div th:replace="footer :: footer"></div>
	<script type="text/javascript" th:inline="javascript">
	
		$().ready(function() {
	        validateRule();
        });
        function validateRule() {
	        var icon = "<i class='fa fa-times-circle'></i> ";
	        $("#editForm").validate({
	            rules : {
	                name : {
		                required : true
	                },
	                email : {
	                    required : true,
	                    email : true
	                },
	            },
	            messages : {

	                name : {
		                required : icon + "请输入姓名"
	                },
	                email : icon + "请输入您的E-mail",
	            }
	        })
        }
        $.validator.setDefaults({
	        submitHandler : function() {
		        $("#roleIds").val(getCheckedRoles());
		        yimo.ajaxPut({
		            url : ctx + "sys/user/update",
		            data : $('#editForm').serialize(),
		            needClose : true,
		            parentRefresh : true,
		        });
	        }
        });

        function getCheckedRoles() {
	        var adIds = "";
	        $("input:checkbox[name=role]:checked").each(function(i) {
		        if (0 == i) {
			        adIds = $(this).val();
		        } else {
			        adIds += ("," + $(this).val());
		        }
	        });
	        return adIds;
        }

        /*用户管理-修改-选择部门树*/
        function selectDeptTree() {
	        layer.open({
	            type : 2,
	            title : "选择部门",
	            area : [ '300px', '450px' ],
	            content : ctx + "sys/dept/treeView"
	        })
        }

        function loadDept(deptId, deptName) {
	        $("#deptId").val(deptId);
	        $("#deptName").val(deptName);
        }
	</script>
</body>
</html>
